home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- This is a very simple speech demo. A large X window opens and changes colors
- among red, green, blue, yellow, black, & white when the color name is spoken.
-
- The templates for color names should be placed in
- /usr/share/data/speech/templates/SpeakColors
-
- Stephen Junkins, March 12, 1994.
- Virtual Reality Systems Laboratory
- Computer Science Department
- Clemson University
- Clemson, South Carolina
- */
-
- #include <stdio.h>
- #include <assert.h>
- #include <X11/Xlib.h>
- #include <X11/Xresource.h>
- #include <speech/Recognizer.h>
- #include <speech/Word.h>
- #include <speech/WordCallbackBindings.h>
- #include <speech/Vocabulary.h>
- #include <speech/Condition.h>
- #include <speech/Event.h>
- #include <speech/Error.h>
- #include <speech/Shorthand.h> /* required for C API */
-
- static const int X = 100 ;
- static const int Y = 100 ;
- static const int W = 800 ;
- static const int H = 800 ;
-
- #define RED 1
- #define COMBO_RG 2
- # define YELLOW 2
- #define GREEN 3
- #define COMBO_GB 4
- # define CYAN 4
- #define BLUE 5
- #define COMBO_RB 6
- # define MAGENTA 6
- #define BLACK 7
- #define WHITE 8
-
-
- /* Declarations */
- char hello[] = {"Demo of SGI Speech Software using C API"};
-
- long create_color(
- Display* display, Colormap colormap,
- unsigned short red, unsigned short green, unsigned short blue )
- {
- XColor tmpColor;
-
- tmpColor.red = red;
- tmpColor.green = green;
- tmpColor.blue = blue;
-
- if(XAllocColor(display, colormap, &tmpColor) == 0)
- fprintf(stderr,"Unable to allocate color.\n");
-
- return tmpColor.pixel ;
- }
-
- create_colors(display, window, colors)
- Display *display;
- Window window;
- long *colors;
- {
- Colormap colormap;
- int screen;
-
- screen = DefaultScreen (display);
-
- /* Create an X colormap structure: */
- colormap = XCreateColormap(display, window,
- DefaultVisual(display, screen), AllocNone);
- XSetWindowColormap(display, window, colormap);
-
- colors[RED] = create_color( display, colormap, 65530, 0, 0 ) ;
- colors[COMBO_RG] = create_color( display, colormap, 65530, 65530, 0 ) ;
- colors[GREEN] = create_color( display, colormap, 0, 65530, 0 ) ;
- colors[COMBO_GB] = create_color( display, colormap, 0, 65530, 65530 ) ;
- colors[BLUE] = create_color( display, colormap, 0, 0, 65530 ) ;
- colors[COMBO_RB] = create_color( display, colormap, 65530, 0, 65530 ) ;
- colors[BLACK] = create_color( display, colormap, 0, 0, 0 ) ;
- colors[WHITE] = create_color( display, colormap, 65530, 65530, 65530 ) ;
- }
-
-
- /** Globals: */
- long colors[256];
- Window window ;
- Display *display;
- GC colorgc;
-
-
- void setColor( const Event* event, void* v )
- {
- XSetForeground (display, colorgc, colors[(int)v]);
- XFillRectangle(display, window, colorgc, 0, 0, W, H);
- }
-
- void quit( const Event* event, void* v )
- {
- exit(0);
- }
-
- void usage( const char* const progName )
- {
- fprintf( stderr, "usage <word1> <word2>\n" ) ;
- fflush( stderr ) ;
- }
-
- int main( int argc, char* argv[] )
- {
- XEvent event ;
-
- Vocabulary* localWords ;
- Vocabulary* globalWords ;
-
- unsigned char swapConditionsUsingVocabularies = 0 ;
-
- char* applicationClass = "SpeakColors" ;
- char* applicationName = argv[0] ;
-
- char fileName[256] ;
- XrmDatabase xrmDatabase ;
- unsigned long valuemask;
- XVisualInfo *visual, gob;
- XSetWindowAttributes attrib;
- int count;
-
- Recognizer* recognizer ;
-
- sprintf( fileName, "%s/.Xdefaults", getenv( "HOME" ) ) ;
- xrmDatabase = XrmGetFileDatabase( fileName ) ; /* toolkit-dep */
-
- /** Create a recognizer: **/
- recognizer = Recognizer_new(
- applicationClass, applicationName, xrmDatabase,
- "", /* default display, program name */
- Recognizer_RecognitionInterest()
- /* | Recognizer_RejectionInterest() */
- /* | Recognizer_AmbiguousInterest() */
- /* | Recognizer_ErrorInterest() */ ) ;
- assert( Recognizer_status( recognizer ) == Error_OK ) ;
- display = Recognizer_dpy( recognizer );
- XSpeechSetEnable (display, SpeechEnableNormal);
-
- /* words with global focus */
- {
- ActionCallbackBinding globalActionFunctionBindings[] = {
- "quit_colors", quit, (void*)0,
- (char*)0, (CallbackFunctionPointer)0, (void*)0,
- } ;
-
- Condition* globalCondition = Condition_newGlobal() ;
- Recognizer_newWords( recognizer, globalActionFunctionBindings,
- globalCondition, &globalWords ) ;
- if( Recognizer_status( recognizer ) != Error_OK )
- {
- fprintf( stderr, "trouble loading global words\n" ) ;
- fflush( stderr ) ;
- }
- Condition_delete( globalCondition ) ;
- }
-
-
- /* words with window(local) focus */
- {
- ActionCallbackBinding localActionFunctionBindings[] = {
- "red", setColor, (void*)RED,
- "green", setColor, (void*)GREEN,
- "blue", setColor, (void*)BLUE,
- "yellow", setColor, (void*)YELLOW,
- "cyan", setColor, (void*)CYAN,
- "magenta", setColor, (void*)MAGENTA,
- "white", setColor, (void*)WHITE,
- "black", setColor, (void*)BLACK,
- "quit", quit, (void*)0,
- (char*)0, (CallbackFunctionPointer)0, (void*)0,
- } ;
-
- /**
- Create a Window (need win for specification of following local words):
- **/
- int screen = DefaultScreen( Recognizer_dpy( recognizer ) ) ;
- Window root = RootWindow( Recognizer_dpy( recognizer ), screen ) ;
-
- long white = WhitePixel(Recognizer_dpy(recognizer), screen ) ;
- long black = BlackPixel(Recognizer_dpy(recognizer), screen ) ;
- window = XCreateSimpleWindow( Recognizer_dpy( recognizer ), root,
- X, Y, W, H, 1, white, black ) ;
- XMapWindow( Recognizer_dpy( recognizer ), window ) ;
-
- /* GC creation and initialization */
- colorgc = XCreateGC (display, window, 0, 0);
- create_colors (display, window, colors);
-
-
- {
- Condition* localCondition = Condition_newWindow( window ) ;
- Recognizer_newWords( recognizer, localActionFunctionBindings,
- localCondition, &localWords ) ;
- if( Recognizer_status( recognizer ) != Error_OK )
- {
- fprintf( stderr, "trouble loading local words\n" ) ;
- fflush( stderr ) ;
- }
- Condition_delete( localCondition ) ;
- }
- }
-
-
- /* toolkit-dependent modification here */
- do
- {
- XNextEvent( Recognizer_dpy( recognizer ), &event ) ;
-
- if( Recognizer_isSpeechEvent( recognizer, &event ) )
- Recognizer_processEvent( recognizer, &event ) ;
- else
- ; /* process as other/normal event */
-
- } while( event.type != DestroyNotify ) ;
-
- XrmDestroyDatabase( xrmDatabase ) ;
-
- {
- Error retVal = Recognizer_status( recognizer ) ;
- Recognizer_delete( recognizer ) ;
- return retVal ;
- }
- }
-
-